package com.ij.media.web;

import com.ij.media.model.VideoVo;
import com.ij.media.service.VideoService;
import com.ij.sso.utils.ReturnUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/video")
public class VideoController {
    @Autowired
    private VideoService videoService;
    @RequestMapping("/importExcel")
    public ReturnUtil importExcel(@RequestParam("file")MultipartFile file) throws Exception{
        String fileName = file.getOriginalFilename();

            if (videoService.batchImportExcel(fileName,file)){
                return ReturnUtil.success();
            }else {
                return ReturnUtil.fail();
            }
    }

    @RequestMapping("/getVideoListByCondition")
    public ReturnUtil getVideoListByCondition(VideoVo videoVo){
        return ReturnUtil.success(videoService.getVideoListByCondition(videoVo));

    }

    @RequestMapping(value="/{randomId}", method= RequestMethod.DELETE)
    public ReturnUtil deleteByRandomId(@PathVariable String randomId){
        if (StringUtils.isEmpty(randomId)){
            return ReturnUtil.fail();
        }
        return ReturnUtil.success(videoService.deleteByRandomId(randomId));
    }
}
